//app.js
App({
  globalData: {
    reqUrl:'https://wx.woqutech.cn/Mobile/Menstruation/',
    userInfo: null,
    isFirst: true,
    isFirst2: true,
    isRec: '1',
    Url:'',
    sessionId: '',
    setting:{},
    beginDate:'',
    userData:'',
    cb: function () { }
  },
  
  onLaunch: function () {
    var that =this;
    wx.login({
      success: function (resc) {
        wx.request({
          url: that.globalData.reqUrl+"onLogin?code=" + resc.code,
          success: function (ress) {
            if(ress.data.user.nickName){
              that.globalData.userData = false;
            }else{
              that.globalData.userData = true ;
            };
            wx.request({
              url: that.globalData.reqUrl +"getConfig?sessionId=" + ress.data.sessionId,
              success: function (r) {
                wx.request({
                  url: that.globalData.reqUrl +"records?&sessionId=" + ress.data.sessionId,
                  success: function (da) {
                    if(da.data.latest.beginDate){
                      that.globalData.beginDate = da.data.latest.beginDate;
                      that.globalData.isFirst = false;
                      that.globalData.isFirst2 = false;
                      that.globalData.setting = r.data.data;
                    }else{
                      that.globalData.isFirst = true;
                      that.globalData.isFirst2 = true;
                    };
                      that.globalData.sessionId = ress.data.sessionId;
                      that.globalData.cb(ress.data.sessionId);
                  }
                });
              },
            });
          }
        });
        
      }
    })

    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
})